#ifndef MAWINDOW_H
#define MAWINDOW_H
#include <QApplication>
#include <QtGui/QMainWindow>
#include <QtGui/QStackedWidget>
#include <QtGui/QToolBar>
#include <QtGui/QMenu>
#include <QtGui/QAction>
#include <QProcess>
#include <QTextCodec>
#include <QTextBrowser>
#include <QListWidgetItem>
#include <QCompleter>
#include <QStringListModel>
#include <QMenuBar>
#include <QStatusBar>
#include <QPrintDialog>
#include <QtGui>

#include "matoolbutton.h"
#include "geometry/KSegView.h"
#include "geometry/KSegDocument.h"
#include "calculator/calculatorwidget.h"
#include "plot/plotwidget.h"
#include "plot/plotview.h"
#include "help/helpwidget.h"


#define MAXTOOLBUTTON 5
#define VERSION "1.0"

class MAToolButton;
class CalculatorWidget;
class HelpWidget;

class MAWindow : public QMainWindow
{
    Q_OBJECT

public:
    MAWindow(KSegDocument *doc = 0);
    ~MAWindow();
    void styleChanged(QWidget*,const QString &styleName);
    void changeStackedWidget(MAToolButton *);
    void helpText(QString fulltext);
private:
    void createActions();
    void createMenus();
    void createWidgets(KSegDocument *geoDoc);
    void createToolBars();
    void createStatusBar();
    void closeEvent(QCloseEvent *ev);
    static bool openFile(QString fileName,MAWindow *win);
    void changeDocument(KSegDocument *doc);

    QAbstractItemModel *modelFromFile(const QString& fileName);

    vector<QString> getValidConstructionFiles();
    void updatePlayBox();

    void geoPrint();
    void calPrint();
    void graphPrint();
    void geoExportToImage();

public slots:
    void fileNewCalculate();
    void fileNewSketch();
    void fileNewConstruction();
    void fileSaveAs();
    void fileSave();
    void fileOpen();
    void filePrint();
    void fileExportToImage();
    void fileChooseLanguage();
    bool closingGeoDoc();
    bool exitProgram();

    void updateStatusBar(const QString&);
    void help();
    void activateHelpModule(QListWidgetItem* item);
    void activateHelpModule(QTreeWidgetItem* item, int);
/* Constructions */

    void editGeoPreferences();
//new menu
    void newGeoSegment();  
    void newGeoIntersectionPoint();
    void newGeoMidpoint();
    void newGeoRay();
    void newGeoLine();
    void newGeoPerpendicularLine();
    void newGeoCircleByCenterAndPoint();
    void newGeoArcByThreePoints();
    void newGeoAngleBisector();
    void newGeoLocus();
    void newGeoEndpoints();
    void newGeoCenterPoint();
    void newGeoPolygon();
    void newGeoArcSector();
    void newGeoArcSegment();
    void newGeoCircleInterior();
//measure menu
    void measureGeoDistance();
    void measureGeoLength();
    void measureGeoRadius();
    void measureGeoAngle();
    void measureGeoRatio();
    void measureGeoSlope();
    void measureGeoArea();
    //void measureGeoCalculate();
//transform
    void transformGeoChooseVector();
    void transformGeoChooseMirror();
    void transformGeoChooseCenter();
    void transformGeoChooseAngle();
    void transformGeoChooseRatio();
    void transformGeoClearChoosen();
    void transformGeoTranslate();
    void transformGeoReflect();
    void transformGeoScale();
    void transformGeoRotate();

    void initialConstruction();
    void finalConstruction();
    void givenConstruction();
    void normalConstruction();
    void recurseConstruction();

    void quickPlay(QString);
    void quickPlaySetDirectory();

    void viewPan();
    void viewZoom();
    void viewZoomFit();
    void resetView();
    void updateMenus();

    void restartMaxima();
    void destroyedMaxima();
    void helpManual();
    void about();
protected slots:
    void editUndo();
    void editRedo();
    void editDelete();
    void editToggleLabels();
    void editHideLabels();
    void editShowLabels();
    void editChangeLabel();
    void editHide();
    void editShowHidden();
    void editChangeNumberOfSamples();
    void editShowSelectionGroupDialog();

    void editColorBlack();
    void editColorGray();
    void editColorRed();
    void editColorGreen();
    void editColorBlue();
    void editColorYellow();
    void editColorMagenta();
    void editColorCyan();
    void editColorOther();

    void editPointstyleLargecircle();
    void editPointstyleMediumcircle();
    void editPointstyleSmallcircle();

    void editLinestyleSolid();
    void editLinestyleDashed();
    void editLinestyleDotted();
    void editLinestyleThin();
    void editLinestyleNormal();
    void editLinestyleThick();

    void editFont10();
    void editFont14();
    void editFont20();
    void editFont30();
    void editFontFont();

    void sendCommand(QString);
    void readResultMaxima();

signals:
    void sendResult(QString);

private:
    MAToolButton * toolButtons[MAXTOOLBUTTON];
    //Menu
    QMenu *fileMenu;
    QMenu *editMenu;
    QMenu *viewMenu;
    QMenu *newMenu;
    QMenu *measureMenu;
    QMenu *transformMenu;
    QMenu *playMenu;
    QMenu *construction;
    QMenu *maximaMenu;
    QMenu *graphMenu;
    QMenu *helpMenu;

    //child Menu and Action
    QMenu *fileNewMenu;
    QAction *fileNewSketAction;
    QAction *fileNewConsAction;
    QAction *fileNewCalAction;
    QAction *saveAction;
    QAction *saveAsAction;
    QAction *openAction;
    QAction *printAction;
    QAction *fileExportAction;
    QAction *exitAction;

    QAction *editUndoAct;
    QAction *editRedoAct;
    QAction *editDeleteObjectAct;
    QAction *editToggleLabelAct;
    QAction *editHideLabelAct;
    QAction *editShowLabelAct;
    QAction *editChangeLabelAct;
    QAction *editHideObjectAct;
    QAction *editUnhideAllAct;
    QMenu *editColor;
    QAction *editColorBlackAct;
    QAction *editColorGrayAct;
    QAction *editColorRedAct;
    QAction *editColorGreenAct;
    QAction *editColorBlueAct;
    QAction *editColorYellowAct;
    QAction *editColorMagentaAct;
    QAction *editColorCyanAct;
    QAction *editColorOtherAct;
    QMenu *editLineStyle;
    QAction *editLinestyleSolidAct;
    QAction *editLinestyleDashedAct;
    QAction *editLinestyleDottedAct;
    QAction *editLinestyleThinAct;
    QAction *editLinestyleNormalAct;
    QAction *editLinestyleThickAct;
    QMenu *editPointStyle;
    QAction *editPointStyleLargecircleAct;
    QAction *editPointStyleMediumcircleAct;
    QAction *editPointStyleSmallcircleAct;

    QMenu *editFontMenu;
    QAction* editFontSize10;
    QAction* editFontSize14;
    QAction* editFontSize20;
    QAction* editFontSize30;
    QAction* editFontFontAct;

    QAction *editChangeNumberOfSampleAct;
    QAction *editPreferencesAct;
    QAction *editSelectionGroupsAct;


    QAction *viewPanAct;
    QAction *viewZoomAct;
    QAction *viewZoomToFitAct;
    QAction *viewOriginalAct;

    QAction *newIntersectionPoint;
    QAction *newSegment;
    QAction *newMidpoint;
    QAction *newRay;
    QAction *newLine;
    QAction *newPerpendicularLine;
    QAction *newCircleByCenterAndPoint;
    QAction *newArcByThreePoints;
    QAction *newAngleBisector;
    QAction *newLocus;
    QAction *newEndpoints;
    QAction *newCenterPoint;
    QAction *newPolygon;
    QAction *newArcSector;
    QAction *newArcSegment;
    QAction *newCircleInterior;

    QAction *measureDistance;
    QAction *measureLength;
    QAction *measureRadius;
    QAction *measureAngle;
    QAction *measureRatio;
    QAction *measureSlope;
    QAction *measureArea;

    QAction *transformChooseVector;
    QAction *transformChooseMirror;
    QAction *transformChooseCenter;
    QAction *transformChooseAngle;
    QAction *transformChooseRatio;
    QAction *transformClearChoosen;
    QAction *transformTranslate;
    QAction *transformReflect;
    QAction *transformScale;
    QAction *transformRotate;

    QAction *makeNormal;
    QAction *makeGiven;
    QAction *makeFinal;
    QAction *makeInitial;
    QAction *recurse;

    QAction *changeDir;

    QAction *grazoomoutAct;
    QAction *grazoominAct;

    QAction *maximaAct;

    QToolBar *helpToolBar;
    QAction *backAct, *forwardAct, *homeAct;
    QAction *zoominAct, *zoomoutAct;

    QAction *helpAboutAct;
    QAction *helpAboutQtAct;
    QAction *helpManualAct;

    QString helpDir;

    QComboBox *geoPlayBox;

    QToolBar *fileToolBar;
    QToolBar *playToolBar;
    QToolBar *geoViewToolBar;
    QToolBar *geoNewToolBar;
    QToolBar *geoMeasureToolBar;
    QToolBar *geoTransformToolBar;


    QToolBar *mainToolBar;
    QStackedWidget *MAStackedWidget;

    QTextBrowser * welcomeView;
    CalculatorWidget * calView;
    KSegView *geoView;
    PlotWidget *graphView;
    QTextBrowser * helpView;
    HelpWidget *helpDocked;
    static QString quickPlayDirectory;
    QProcess * maxima;


    QCompleter *completer;
};

#endif // MAWINDOW_H
